package cn.heycm.seata.product.dao;

import cn.heycm.seata.product.dao.entity.Product;
import cn.heycm.seata.product.dao.mapper.ProductMapper;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

/**
 * @author hey
 * @version 1.0
 * @since 2024/9/11 21:36
 */
@Repository
public class ProductRepository {

    @Autowired
    private ProductMapper productMapper;

    @GlobalTransactional
    public void save(Integer productId, String productName) {
        Product product = new Product();
        product.setId(productId);
        product.setProductName(productName);
        boolean success = productMapper.updateByPrimaryKeySelective(product) > 0;
        Assert.isTrue(success, "更新失败");
    }
}
